local key = KEYS[1]
local noteId = ARGV[1]
local timestamp = ARGV[2]

-- 校验Key是否存在
local exist = redis.call("EXISTS", key)
if exist == 0 then
    return -1
end

local size = redis.call("ZCARD", key)

if size >= 100 then
    redis.call('ZPOPMIN', key)
end

redis.call("ZADD", key, timestamp, noteId)
return 0